// 这个模块主要提供 一些方法和类型

// 管理员默认路由
let adminRouter = [
    {
        path: '/',
        name: 'Home',

        redirect: "/workform",
        children: [
            {
                path: 'classJur',     // 对老师，学生的权限设置
                name: 'classJur',
                meta: {
                    id: 41,
                    icon: "el-icon-position",
                    title: "分类权限管理",
                    roles: ["admin"]
                },

            },
            {
                path: 'userJur',     // 对单独地用户的权限设置
                name: 'userJur',
                meta: {
                    id: 42,
                    icon: "el-icon-thumb",
                    title: "用户权限管理",
                    roles: ["admin"]
                },

            },
            {
                path: 'workform',     // 表格
                name: 'workform',
                meta: {
                    id: 11,
                    icon: "el-icon-c-scale-to-original",
                    title: "升学就业表格",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'workEcharts',    // echarts可视化
                name: 'workEcharts',
                meta: {
                    id: 21,
                    icon: "el-icon-picture-outline",
                    title: "升学就业可视化",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'forum',  // 论坛
                name: 'forum',
                meta: {
                    id: 31,
                    icon: "el-icon-chat-line-square",
                    title: "学生论坛",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'account',  // 账号管理，个人信息修改中心
                name: 'account',
                meta: {
                    id: 51,
                    icon: "el-icon-s-custom",
                    title: "账号信息管理",
                    roles: ["admin", "teacher", "student"]
                },

            },

            {
                path: 'authentication',  // 老师资格认证模块
                name: 'authentication',
                meta: {
                    id: 53,
                    icon: "el-icon-menu",
                    title: "教师资格认证",
                    roles: ["admin"]
                },

            },

            {
                path: 'upload',  // 就业信息上传
                name: 'upload',
                meta: {
                    id: 52,
                    icon: "el-icon-upload",
                    title: "就业信息上传",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'employment',  // 学历结构
                name: 'employment',
                meta: {
                    id: 22,
                    icon: "el-icon-mobile",
                    title: "学历结构",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'sexstract',  // 性别占比
                name: 'sexstract',
                meta: {
                    id: 23,
                    icon: "el-icon-female",
                    title: "性别占比",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'map',  // 就业分布
                name: 'map',
                meta: {
                    id: 24,
                    icon: "el-icon-map-location",
                    title: "就业分布",
                    roles: ["admin", "teacher", "student"]
                },

            },

        ]
    },
]

// 老师默认路由 最大的权限
let teacherRouter = [
    {
        path: '/',
        name: 'Home',

        redirect: "/workform",
        children: [
            {
                path: 'workform',     // 表格
                name: 'workform',
                meta: {
                    id: 11,
                    icon: "el-icon-c-scale-to-original",
                    title: "升学就业表格",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'workEcharts',    // echarts可视化
                name: 'workEcharts',
                meta: {
                    id: 21,
                    icon: "el-icon-picture-outline",
                    title: "升学就业可视化",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'forum',  // 论坛
                name: 'forum',
                meta: {
                    id: 31,
                    icon: "el-icon-chat-line-square",
                    title: "学生论坛",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'account',  // 账号管理，个人信息修改中心
                name: 'account',
                meta: {
                    id: 51,
                    icon: "el-icon-s-custom",
                    title: "账号信息管理",
                    roles: ["admin", "teacher", "student"]
                },

            },

            {
                path: 'upload',  // 就业信息上传
                name: 'upload',
                meta: {
                    id: 52,
                    icon: "el-icon-upload",
                    title: "就业信息上传",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'employment',  // 学历结构
                name: 'employment',
                meta: {
                    id: 22,
                    icon: "el-icon-mobile",
                    title: "学历结构",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'sexstract',  // 性别占比
                name: 'sexstract',
                meta: {
                    id: 23,
                    icon: "el-icon-female",
                    title: "性别占比",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'map',  // 就业分布
                name: 'map',
                meta: {
                    id: 24,
                    icon: "el-icon-map-location",
                    title: "就业分布",
                    roles: ["admin", "teacher", "student"]
                },

            },

        ]
    },
]

// 学生默认路由  最大的权限
let studentRouter = [
    {
        path: '/',
        name: 'Home',

        redirect: "/workform",
        children: [
            {
                path: 'workform',     // 表格
                name: 'workform',
                meta: {
                    id: 11,
                    icon: "el-icon-c-scale-to-original",
                    title: "升学就业表格",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'workEcharts',    // echarts可视化
                name: 'workEcharts',
                meta: {
                    id: 21,
                    icon: "el-icon-picture-outline",
                    title: "升学就业可视化",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'forum',  // 论坛
                name: 'forum',
                meta: {
                    id: 31,
                    icon: "el-icon-chat-line-square",
                    title: "学生论坛",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'account',  // 账号管理，个人信息修改中心
                name: 'account',
                meta: {
                    id: 51,
                    icon: "el-icon-s-custom",
                    title: "账号信息管理",
                    roles: ["admin", "teacher", "student"]
                },

            },

            {
                path: 'upload',  // 就业信息上传
                name: 'upload',
                meta: {
                    id: 52,
                    icon: "el-icon-upload",
                    title: "就业信息上传",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'employment',  // 学历结构
                name: 'employment',
                meta: {
                    id: 22,
                    icon: "el-icon-mobile",
                    title: "学历结构",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'sexstract',  // 性别占比
                name: 'sexstract',
                meta: {
                    id: 23,
                    icon: "el-icon-female",
                    title: "性别占比",
                    roles: ["admin", "teacher", "student"]
                },

            },
            {
                path: 'map',  // 就业分布
                name: 'map',
                meta: {
                    id: 24,
                    icon: "el-icon-map-location",
                    title: "就业分布",
                    roles: ["admin", "teacher", "student"]
                },

            },

        ]
    },

]

// 导出一个专门处理 权限id数组和这儿的路由表的对应关系的函数
function handleJur(arr) {
    let newadminRouter = [{
        path: '/',
        name: 'Home',
        redirect: "/workform",
        children: []
    }]

    for (let i = 0; i < arr.length; i++) {
        for (let j = 0; j < studentRouter[0].children.length; j++) {
            if (studentRouter[0].children[j].meta.id == arr[i]) {
                newadminRouter[0].children.push(studentRouter[0].children[j])
            }
        }
    }

    // console.log(newadminRouter)

    return newadminRouter
}

// 导出一个用于处理 判断用户是 mobile 或者 pc 的
function getMachine(req) {
    var deviceAgent = req.headers["user-agent"].toLowerCase();
    var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/);
    if (agentID) {      // 如果是pc agentID==null
        return "mobile";
    } else {
        return "pc";
    }
}

module.exports = {
    getMachine,
    handleJur,
    adminRouter,
    teacherRouter,
    studentRouter
}